Data Representation
Number systems
Understand binary
- Any form of data needs to be converted to binary to be processed by a computer.
- The basic building block in all computers is the binary number system.
Switch
Switch ON is 1 and OFF is 0.
Digit weight
- Every one of us is used to the decimal or denary (base 10) number system. This uses the digits 0 to 9 which are placed in ‘weighted’ columns.
10000 | 1000 | 100 | 10 | 1 |
---|---|---|---|---|
104 | 103 | 102 | 101 | 100 |
3 | 1 | 4 | 2 | 1 |
- Example: 3x10000 + 1x1000 + 4x100 + 2x10 + 1x1 = 31421
Binary to denary
- Except for denary, we use binary(base 2) and hexadecimal(base 16) number system in the computer.
Denary value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Binary value | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Hexadecimal value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
- The binary system uses 1s and 0s only which gives these corresponding weightings.
- We can convert binary number to denary according to digit weightings.
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
- Example: 1110 11102 = 128 + 64 + 32 + 8 + 4 + 2 = 23810
2 to 10
Convert binary to denary: 0011 0011 ?
2 to 10
Which number is closest to 0011 1111 ?
2 to 10
Which numbers are less than 1011 1101 ?
Hexadecimal to denary
- The hexadecimal system is very closely related to the binary system.
- Hexadecimal is a base 16 system.
- Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are used to represent hexadecimal digits.
- A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
- We can convert hexadecimal number to denary according to digit weightings.
65536 | 4096 | 256 | 16 | 1 |
---|---|---|---|---|
164 | 163 | 162 | 161 | 160 |
0 | 1 | 1 | 2 | 3 |
Example: 0112316 = 1x4096 + 1x256 + 2x16 + 3x1 = 438710
16 to 10
Convert hexadecimal to denary: ABC ?
16 to 10
Convert hexadecimal to denary: DE0 ?
Use of the hexadecimal system
When the memory contents are output to a printer or monitor, this is known as a memory dump.
Denary to binary
- Converting from denary to binary is slightly more complex.
- This method involves successive division by 2 until the result is 0; the remainders are then written from bottom to top to give the binary value.
Divider | Result | Remainder | Process |
---|---|---|---|
2 | 107 | ||
2 | 53 | 1 | 107 ➗ 2 = 53 ……1 |
2 | 26 | 1 | 53 ➗ 2 = 26 ……1 |
2 | 13 | 0 | 26 ➗ 2 = 13 ……0 |
2 | 6 | 1 | 13 ➗ 2 = 6 ……1 |
2 | 3 | 0 | 6 ➗ 2 = 3 ……0 |
2 | 1 | 1 | 3 ➗ 2 = 1 ……1 |
0 | 1 | 1 ➗ 2 = 0 ……1 |
- Example: 10710 = 110 10112
10 to 2
Convert denary to binary: 41 ?
10 to 2
Convert denary to binary: 252 ?
Denary to hexadecimal
- Converting from denary to hexadecimal is slightly similar with denary to binary.
- This method involves successive division by 16; the remainders are then written from bottom to top to give the hexadecimal value.
Divider | Result | Remainder | Process |
---|---|---|---|
16 | 2004 | ||
16 | 125 | 4 | 2004 ➗ 16 = 125 ……4 |
16 | 7 | 13(D) | 125 ➗ 16 = 7 ……13(D) |
16 | 0 | 7 | 7 ➗ 16 = 0 ……7 |
- Example: 200410 = 7D416
10 to 16
Convert denary to hexadecimal: 2022 ?
10 to 16
Convert denary to hexadecimal: 252 ?
Binary to hexadecimal
- Since 16 = 24, four binary digits are equivalent to each hexadecimal digit.
Binary value | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hexadecimal value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
Denary value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
- Example: 11111000012 = 0011 1110 00012 = 3E116
2 to 16
Convert binary to hexadecimal: 1001011 ?
Hexadecimal to binary
Since 16 = 24, one hexadecimal digit are equivalent to four binary digits.
Example: 45A16 = 0100 0101 10102
16 to 2
Convert hexadecimal to binary: 6C ?
Positive numbers in binary
- There are two methods to represent both positive and negative numbers.
- In one’s complement, each digit in the binary number is inverted.
- In two’s complement, each digit in the binary number is inverted and a ‘1’ is added to the right-most bit.
Decimal value | Two's-complement representation |
---|---|
0 | 0000 0000 |
1 | 0000 0001 |
2 | 0000 0010 |
126 | 0111 1110 |
127 | 0111 1111 |
−128 | 1000 0000 |
−127 | 1000 0001 |
−126 | 1000 0010 |
−2 | 1111 1110 |
−1 | 1111 1111 |
Two’s complement
- The two’s complement uses these weightings for an 8-bit number representation.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
104 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
-104 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
- For example, 104 in binary is 0 1 1 0 1 0 0 0.
- To find the binary value for −104 using two’s complement:
- Invert the digits: 1 0 0 1 0 1 1 1 (+104 in denary)
- Add 1: 1
- Which gives: 1 0 0 1 1 0 0 0 (−104 in denary)
Two's complement
Use two's complement to represent -114 with 8 bits.
Binary addition
bianry addtion
- 0 + 0 = 0
- 1 + 0 = 1 (sum 1 and carry 0)
- 1 + 1 = 10 (sum 0 and carry 1 )
- 1 + 1 + (carry 1) = 11= sum 1 and carry 1
- Add 0 0 1 0 0 1 0 1 (37 in denary) and 0 0 1 1 1 0 1 0 (58 in denary).
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
37 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
+ | ||||||||
58 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 |
= | ||||||||
Carry | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
Sum | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
- The sum is 0101 1111, which is 95 in denary.
Binary addition
Calculate 0011 1001 + 0010 1001.
Binary subtraction
- Carry out the subtraction 95 – 68 in binary.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | ||
---|---|---|---|---|---|---|---|---|---|
95 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | |
- | |||||||||
68 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | |
-68 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | |
Carry | 1 (Drop it) | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
Sum | 1 (Drop it) | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 |
- The result is 0001 1011, which is 27 in denary.
Binary subtraction
Calculate 0110 0011 - 0011 0000.
Overflow error
- Add 0 1 0 1 0 0 1 0 (82 in denary) and 0 1 0 0 0 1 0 1 (69 in denary).
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
82 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
+ | ||||||||
69 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
= | ||||||||
Carry | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Sum | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 1 |
- The sum is 1001 0111, which is -105 (Incorrect)
Overflow error
- The expected answer for 82 + 69 is 151, which is out of range for the 8 bits register (-128~127), this is known as an overflow error.
Logical shifts
- The positive binary integer is multiplied or divided according to the shift performed.
- Bits shifted from the end of the register are lost and zeros are shifted in at the opposite end of the register.
- The most significant bit(s) or least significant bit(s) are lost.
Logical shift
Right shift 1011 0101 with 2 digits?
Measurement of the size of computer memories
TIP
A binary digit is referred to as a BIT. 4 bits are 1 NIBBLE. 8 bits are 1 BYTE.
Storage Device
Measurement | Number of bytes |
---|---|
1 kilobyte(1 KB) | 103 |
1 megabyte(1 MB) | 106 |
1 gigabyte(1 GB) | 109 |
1 terabyte(1 TB) | 1012 |
1 petabyte(1 PB) | 1015 |
Computer System
Measurement | Number of bytes |
---|---|
1 kibibyte(1 KiB) | 210 |
1 mebibyte(1 MiB) | 220 |
1 gibibyte(1 GiB) | 230 |
1 tebibyte(1 TiB) | 240 |
1 pebibyte(1 PiB) | 250 |
KB vs KiB
- KB is used in factory and Kib is used in computer system.
Memory size
8GB = ( ) bits?
Memory size
8GiB = ( ) bytes?
Binary-coded decimal (BCD) system
- The binary-coded decimal (BCD) system uses a 4-bit code to represent each denary digit.
0 0 0 0 | 0 | 0 1 0 1 | 5 |
---|---|---|---|
0 0 0 1 | 1 | 0 1 1 0 | 6 |
0 0 1 0 | 2 | 0 1 1 1 | 7 |
0 0 1 1 | 3 | 1 0 0 0 | 8 |
0 1 0 0 | 4 | 1 0 0 1 | 9 |
- Therefore, the denary number 3 1 6 5 would be 0011 0001 0110 0101 in BCD format.
Use of BCD
- The most obvious use of BCD is in the representation of digits on a calculator or clock display.
- Consider adding $0.37 and $0.94 together using fixed-point decimals.
BCD
Convert denary number 271 to BCD format?
ASCII codes and Unicodes
- ASCII (American Standard Code for Information Interchange)
Text is converted to binary to be processed by a computer according to ASCII code.(7 bits per character).
Extended ASCII code
Extended ASCII code use 8 bits per character.
A is stored as 0100 0001
ASCII code
DEC | OCT | HEX | BIN | Symbol | HTML Number | Description |
---|---|---|---|---|---|---|
65 | 101 | 41 | 01000001 | A | A | Uppercase A |
66 | 102 | 42 | 01000010 | B | B | Uppercase B |
67 | 103 | 43 | 01000011 | C | C | Uppercase C |
68 | 104 | 44 | 01000100 | D | D | Uppercase D |
69 | 105 | 45 | 01000101 | E | E | Uppercase E |
70 | 106 | 46 | 01000110 | F | F | Uppercase F |
Unicode
- Unicode allows for a greater range of characters and symbols than ASCII, including different languages and emojis. (16 bits per character)
ASCII
If A is stored as 65 in ASCII code, what is the binary value to store G?
Hexa use
Which items are using hexadecimal?